package org.jypj.dev.task;

import org.jypj.dev.dao.ICreateTableDao;
import org.jypj.dev.util.DateUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by ChenYu on 2017-05-23.
 */
@Component
public class CreateTableTask {
    @Resource
    private ICreateTableDao createTableDao;

    /**
     * 自动生成表
     * 每月15日的凌晨3点触发
     */
    @Scheduled(cron = "0 00 03 15 * ?")
    public void createTable() {
        String yyyy_mm = DateUtils.getNextMonth(new Date(), "yyyy_MM");
        String userWorkTableName = "bs_user_work_" + yyyy_mm;
        String workFileTableName = "ff_work_file_" + yyyy_mm;
        try {
            createTableDao.createUserWorkTable(userWorkTableName);
            System.out.println(userWorkTableName);
        } catch (Exception e) {

        }
        try {
            createTableDao.createWorkFileTable(workFileTableName);
            System.out.println(workFileTableName);
        } catch (Exception ignored) {
        }
    }

}
